// TOWN SCRIPT
//    Town 18: Under Hengest

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
	set_name(6,"Folcwald");
	set_name(7,"Faust");
	set_name(8,"Helsaeg");
	set_name(9,"Cwaldin");
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(10,49,22);
		end();
		}
break;

beginstate 11;
	if (get_flag(18,0) == 250)
		end();
	set_flag(18,0,250);
	set_state_continue(12);
break;

beginstate 12;
	message_dialog("The door opens. You are suddenly seized by cold hands that drag you through chill, winding passages to another cell. The portcullis shuts.","Facing you is someone else. Not another prisoner. In the dim light, you can vaguely tell that this is someone of certain rank.");
	teleport_party(21,28,1);
break;

beginstate 13;
	reset_dialog();
	add_dialog_str(0,"He nods. _Our purpose is merely to know. We need to know your experiences, you purposes, so as to better know our friends and our enemies. Speak._",0);
	add_dialog_str(1,"Folcwald sits stationary in his chair, waiting. Do you speak to him of the events you have been through and witnessed?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	if (choice == 1)
		set_state_continue(15);
	if (choice == 2)
		set_state_continue(14);
break;

beginstate 14;
	message_dialog("He shrugs. _I will wait. Perhaps you wish to know more of our purposes?_","");
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"You recall back to the day when you first arrived on the isle of Ylmir, of your meeting with the Seawyrm agent in Hatherond, and your subsequent exploits. As you tell of these events, Folcwald listens with interest, but raises no questions.",0);
	add_dialog_str(1,"You tell of the meetings with Aeschere, and the state of Ingusi, continuing until the last turn of events that you remember. It's all told without the briefest interruption. When you finish, however, Folcwald still looks at you, waiting.",0);
	add_dialog_str(2,"You think you might have skipped something or other in your narrative, and are just about to go back and cover them, when...",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(16);
break;

beginstate 16;
	reset_dialog();
	add_dialog_str(0,"A face appears on the other side of the portcullis. You can't really make it out. It exchanges some words with Folcwald in a speech unknown to you.",0);
	add_dialog_str(1,"The face disappears. With a quiet rustle, Folcwald stands and moves toward the gate. Opening it, he goes through, then turns to you.",0);
	add_dialog_str(2,"_The stairs are in the east. Look for them when you choose to depart. The king wishes to see you with all due haste._",0);
	add_dialog_str(3,"Then he leaves, and you are alone in the interrogation cell.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(17);
break;

beginstate 17;
	message_dialog("Folcwald has left the cell.","");
	set_flag(18,1,1);
	set_state_continue(21);
break;

beginstate 18;
	if (get_terrain(23,30) == 29)
		set_state_continue(19);
break;

beginstate 19;
	if (get_flag(18,1) >= 1)
		set_state_continue(20);
break;

beginstate 20;
	message_dialog("Someone pulls a hidden lever on the other side, and the portcullis opens.","");
	flip_terrain(23,30);
break;

beginstate 21;
			erase_char(6);
break;

beginstate 22;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
		set_state_continue(23);
		}
break;

beginstate 23;
	message_dialog("You hear clattering.","");
	flip_terrain(41,23);
	flip_terrain(42,23);
	set_flag(100,0,12);	
break;




